package top.bingoz.wanandroid.base

import android.os.Bundle
import android.support.v4.app.Fragment
import dagger.android.AndroidInjection
import dagger.android.AndroidInjector
import dagger.android.DispatchingAndroidInjector
import dagger.android.support.HasSupportFragmentInjector
import javax.inject.Inject

/**
 * @author su
 * @date 2018/7/29
 * @description
 */
abstract class BaseMvpActivity : BaseActivity(), HasSupportFragmentInjector {

    @Inject
    lateinit var supportFragmentInjector: DispatchingAndroidInjector<Fragment>

    var mPresenter = MultiPresenter()

    override fun supportFragmentInjector(): AndroidInjector<Fragment> {
        return supportFragmentInjector
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        AndroidInjection.inject(this)
        bindPresenter(mPresenter)
        mPresenter.attachView(this)
        super.onCreate(savedInstanceState)
    }

    open protected fun bindPresenter(presenter: MultiPresenter) {
    }


    override fun onDestroy() {
        super.onDestroy()
        mPresenter.detachView()
        mPresenter.destroy()
    }

}